import java.util.ArrayList;
import java.util.List;

public class Main {
    private static int outIndex = 1;
    private Double expectedTotalPrice;

    private Double nowTotalPrice = 0.0;

    private List<Shop> allShopList;

    private List<Shop> nowList = new ArrayList<>();

    public static void main(String[] args) {
        String expectPrice = null;
        if(args.length>0) {
            expectPrice = args[0];
        }
        Double expectPrice_ = 1200.0;
        Main main = new Main();
        if (expectPrice != null && !"".equals(expectPrice)) {
            expectPrice_ = Double.valueOf(expectPrice);
//            System.out.println("expectPrice_="+expectPrice_);
            main.setExpectedTotalPrice(expectPrice_);
        }
        System.out.println("预期价格：" + main.getExpectedTotalPrice());
        List<Shop> allShopList = new ArrayList<>();
        allShopList.add(new Shop("高油酸花生油2.5L", 90.0));
        allShopList.add(new Shop("小磨香油400ml*4", 100.0));
        allShopList.add(new Shop("伦敦小熊什锦礼盒808g", 100.0));
        allShopList.add(new Shop("干红葡萄酒750ml*2瓶", 180.0));
        allShopList.add(new Shop("高山寿眉茶叶礼盒500g", 180.0));
        allShopList.add(new Shop("玫瑰花饼礼盒960g", 100.0));
        allShopList.add(new Shop("得利斯盛世经典礼盒3140g", 210.0));
        allShopList.add(new Shop("莉香滇红茶叶礼盒300g", 150.0));
        allShopList.add(new Shop("立白清洁套装3.1kg", 130.0));
        allShopList.add(new Shop("恰恰瓜子+大白兔奶糖组合", 100.0));
        allShopList.add(new Shop("盼盼坚果礼盒1370g", 170.0));
        allShopList.add(new Shop("特级亚麻籽油108L*2桶", 110.0));
        allShopList.add(new Shop("五常大米2.5kg*2袋", 90.0));
        allShopList.add(new Shop("东北干货礼盒1590g", 200.0));
        allShopList.add(new Shop("新疆特色礼盒3000g", 190.0));
        allShopList.add(new Shop("农场麻酱鸡蛋礼盒", 90.0));
        allShopList.add(new Shop("隆力奇蛇油护手霜", 10.0));
        allShopList.add(new Shop("维生素C泡腾片10片装", 10.0));
        allShopList.add(new Shop("手撕鱿鱼105g", 10.0));
        main.setAllShopList(allShopList);
        main.setExpectedTotalPrice(expectPrice_);
        main.work(0);
    }

    public void work(int startIndex) {
        if (this.nowTotalPrice.equals(this.expectedTotalPrice)) {
            System.out.println("排列"+Main.outIndex+" "+this.listToString(this.nowList));
            Main.outIndex += 1;
        } else if (this.nowTotalPrice < this.expectedTotalPrice) {
            for (int i = startIndex; i < this.getAllShopList().size(); i++) {
                if (!this.getNowList().contains(this.getAllShopList().get(i))) {
                    this.getNowList().add(this.getAllShopList().get(i));
                    this.nowTotalPrice += this.getAllShopList().get(i).getPrice();
                    startIndex = i;
                    work(startIndex);
                    this.getNowList().remove(this.getAllShopList().get(i));
                    this.nowTotalPrice -= this.getAllShopList().get(i).getPrice();
                }
            }
        }
//        System.out.println(this.getAllShopList());
//        System.out.println(this.getNowTotalPrice());
//        System.out.println(this.getExpectedTotalPrice());
//        System.out.println(this.getNowList());


    }

    private String listToString(List<Shop> nowList) {
        String res = "";
        for (int i = 0; i < nowList.size(); i++) {
            res += nowList.get(i).getShopName() + "(" + nowList.get(i).getPrice() + ") ";
        }
        return res;
    }

    static class Shop {
        String shopName;
        Double price;

        public Shop(String shopName, Double price) {
            this.shopName = shopName;
            this.price = price;
        }

        public String getShopName() {
            return shopName;
        }

        public void setShopName(String shopName) {
            this.shopName = shopName;
        }

        public Double getPrice() {
            return price;
        }

        public void setPrice(Double price) {
            this.price = price;
        }
    }

    public Double getExpectedTotalPrice() {
        return expectedTotalPrice;
    }

    public void setExpectedTotalPrice(Double expectedTotalPrice) {
        this.expectedTotalPrice = expectedTotalPrice;
    }

    public Double getNowTotalPrice() {
        return nowTotalPrice;
    }

    public void setNowTotalPrice(Double nowTotalPrice) {
        this.nowTotalPrice = nowTotalPrice;
    }

    public List<Shop> getAllShopList() {
        return allShopList;
    }

    public void setAllShopList(List<Shop> allShopList) {
        this.allShopList = allShopList;
    }

    public List<Shop> getNowList() {
        return nowList;
    }

    public void setNowList(List<Shop> nowList) {
        this.nowList = nowList;
    }


}
